//对于axios进行二次封装
import axios from 'axios'

//引入nprogress和它的样式
import nProgress from 'nprogress'
import 'nprogress/nprogress.css'

//利用axios对象的creat()方法，创建一个axios实例
let mockRequests = axios.create({
  baseURL: '/mock',
  timeout: 5000
})

//请求拦截器
mockRequests.interceptors.request.use((config) => {
  nProgress.start()
  return config
})

//响应拦截器
mockRequests.interceptors.response.use(
  (res) => {
    nProgress.done()
    return res.data
  },
  (error) => {
    return Promise.reject(new Error('fail'))
  }
)

export default mockRequests
